/**
 * 用户认证服务
 */

import { BaseApiService } from '../utils/api';
import {
  AppUserRegisterDto,
  AppUserRegisterVo,
  EmailPasswordLoginDto,
  GoogleLoginDto,
  AppleLoginDto,
  CheckResultVo,
} from '../types/api';

export class AuthService extends BaseApiService {
  
  /**
   * 邮箱密码登录
   */
  async emailPasswordLogin(data: EmailPasswordLoginDto): Promise<AppUserRegisterVo> {
    return this.handleResponse(
      this.http.post<AppUserRegisterVo>('/api/auth/emailPassword', data)
    );
  }

  /**
   * Google登錄
   */
  async googleLogin(data: GoogleLoginDto): Promise<AppUserRegisterVo> {
    return this.handleResponse(
      this.http.post<AppUserRegisterVo>('/api/auth/google', data)
    );
  }

  /**
   * Apple登录
   */
  async appleLogin(data: AppleLoginDto): Promise<AppUserRegisterVo> {
    return this.handleResponse(
      this.http.post<AppUserRegisterVo>('/api/auth/apple', data)
    );
  }

  /**
   * 用户注册
   */
  async register(data: AppUserRegisterDto): Promise<AppUserRegisterVo> {
    return this.handleResponse(
      this.http.post<AppUserRegisterVo>('/api/reg/register', data)
    );
  }

  /**
   * 检查用户名是否存在
   */
  async checkUsername(userName: string): Promise<CheckResultVo> {
    return this.handleResponse(
      this.http.get<CheckResultVo>('/api/reg/checkUsername', { userName })
    );
  }

  /**
   * 检查邮箱是否存在
   */
  async checkEmail(email: string): Promise<CheckResultVo> {
    return this.handleResponse(
      this.http.get<CheckResultVo>('/api/reg/checkEmail', { email })
    );
  }

  /**
   * 检查手机号是否存在
   */
  async checkPhone(phonenumber: string): Promise<CheckResultVo> {
    return this.handleResponse(
      this.http.get<CheckResultVo>('/api/reg/checkPhone', { phonenumber })
    );
  }
}

// 导出单例实例
export const authService = new AuthService();
